#include "worker.h"
#include "communication.h"

#include <QDebug>
#include <QTimerEvent>

Worker::Worker(QObject *parent) : QObject(parent)
{
    m_temperatureId = 0;
}

void Worker::timerEvent(QTimerEvent *event)
{
    if (event->timerId() == m_temperatureId) {
        emit temperatureChanged(1);
    }
}

void Worker::onInitialize()
{
    m_temperatureId = startTimer(1000, Qt::PreciseTimer);
    if (m_temperatureId == 0) {
        qDebug() << Q_FUNC_INFO << "startTimer failure";
    } else {
        qDebug() << Q_FUNC_INFO << "startTimer " << m_temperatureId;
    }
}

void Worker::onDestroy()
{
    killTimer(m_temperatureId);
    m_temperatureId = 0;
}
